//
//  CWBaseNavController.swift
//  新浪微博练习02
//
//  Created by 曹魏 on 16/9/24.
//  Copyright © 2016年 itcast. All rights reserved.
//

import UIKit

class CWBaseNavController: UINavigationController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        
        
        
    }
    //重写push方法
    override func pushViewController(_ viewController: UIViewController, animated: Bool) {
        //一旦空实现这个方法,导航控制器无法设置跟视图控制器
        //也就意味着系统的UINavigationController默认实现了push(可以直观地想一下,当我在sb中拖进来一个导航控制器,会默认带一个tableviewcontroller,也就明显的说明了这一点),所以需要重写父类的push方法
        //设置返回按钮
        //判断一下
        let count = childViewControllers.count
        if count > 0 {
            
            viewController.navigationItem.leftBarButtonItem = UIBarButtonItem(title: "返回", imageName: "navigationbar_back_withtext", target: self, action: #selector(back))
            //当进入到子视图控制器的时候,最好隐藏底部的tabbar
            viewController.hidesBottomBarWhenPushed = true
            
        }
        super.pushViewController(viewController, animated: animated)
        
        
        
    }
    @objc private func back() {
        popViewController(animated: true)
    }

}
